# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=pngquant
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.17.0
pkgrel=1
pkgdesc="Command-line utility to quantize PNGs down to 8-bit paletted PNGs (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url='https://pngquant.org/'
license=("BSD")
depends=("${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-lcms2"
         "${MINGW_PACKAGE_PREFIX}-libimagequant")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/kornelski/${_realname}/archive/${pkgver}.tar.gz")
sha256sums=('bc1baa43c814b4416bb63d7b2168d4e5395cfc69a00f8997a595361caa507887')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
#  patch -p1 -i ${srcdir}/0001-min-build-fix.patch
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  rm -rf "${srcdir}"/build-${CARCH} || true
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${CARCH}"
  cd "${srcdir}"/build-${CARCH}
  msg2 "PWD $(pwd)"
  if [ "${CARCH}" = "i686" ]; then
    SSE="--disable-sse"
  else
    SSE="--enable-sse"
  fi
  ./configure --prefix=${MINGW_PREFIX} \
    --with-libimagequant=${MINGW_PREFIX}/lib/ \
    ${SSE}
  make --jobs=1
}

package() {
  cd "${srcdir}"/build-${CARCH}

  install -dm 0755 ${pkgdir}${MINGW_PREFIX}/bin
  install -dm 0755 ${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}
  install -dm 0755 ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  install -m 0644 -p pngquant.exe \
     ${pkgdir}${MINGW_PREFIX}/bin/pngquant.exe
   install -m 0644 -p CHANGELOG \
      ${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/CHANGELOG
   install -m 0644 -p README.md \
      ${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md
   install -m 0644 -p COPYRIGHT \
       ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYRIGHT
}

